<?php
        if($_SERVER['HTTP_ORIGIN'] == "http://orion.pardus.at") { header('Access-Control-Allow-Origin: http://orion.pardus.at'); }
        else if($_SERVER['HTTP_ORIGIN'] == "http://artemis.pardus.at") { header('Access-Control-Allow-Origin: http://artemis.pardus.at'); }
        else if($_SERVER['HTTP_ORIGIN'] == "http://pegasus.pardus.at") { header('Access-Control-Allow-Origin: http://pegasus.pardus.at'); }
        else { die('0,Information Not coming from Pardus'); }
        
	require_once($_SERVER["DOCUMENT_ROOT"]."/alerter/modules/security_mod.php");
	require_once($_SERVER["DOCUMENT_ROOT"]."/alerter/modules/alert_mod.php");
	
	SecurityMod::loginSighter();
	
//        $level = $_SESSION["alert_account"]->getAdmin();
//	if ($level != 1 && $_SESSION["alert_account"]->getFFMUpload() != 1 && $_SESSION["alert_account"]->getLevel() != "Admin"){
//		print("<div id='po_ffm_info_text'><div type='info' style='display:none;'><div type='error' id='po_invalid_user'>Invalid user</div></div>");
//		SecurityMod::logout();
//	}

	$pid = $_SESSION["alert_account"]->getPilotId();
	$data = json_decode (stripslashes(v($_REQUEST, "data")), true);

	foreach ($data as $tileId => $facilityData) {
		foreach ($facilityData as $dataType => $value) {
			$fac =  new FLogFacility ($pid, $tileId, $value['sector'], $value['timestamp'], $value, $dataType);
			if ($value["navUpdate"] == 'delete_all') {
				AlertMod::deleteAllFLogFacility($tileId);
				break;
			} else {
				AlertMod::addFLogFacility($fac);
			}
		}
	}
?>